
//角色在这里找指令，有则执行并删除

CmdManager = cc.Class.extend({
	cmdHash:null,
	ctor:function(){
		this.cmdHash={}
		
		cc.log("CmdManager")
	},
	addCmd:function(cmd){
		//前后不能同时出现
		if(cmd.name=="fwd")
			this.delCmd("bkw")
		else if(cmd.name=="bkw")
			this.delCmd("fwd")


		this.cmdHash[cmd.name]=cmd;
	},
	processCommand:function(cmd){
		var trans={}
		trans.time=0.1;
		trans.name=cmd.name;

		this.addCmd(trans);
	},
	delCmd:function(name){
		delete this.cmdHash[name];
	},
	hasCmd:function(name){
		if(this.cmdHash[name])
			return true
		else
		{
			return false;
		}
			
	},
	update:function(dt){
		//定时清除命令队列
		var delcmds=[];
		for(k in this.cmdHash)
		{
			var cmd=this.cmdHash[k];
			cmd.time-=dt;

			if(cmd.time<=0)
				delcmds.push(cmd.name)
		}

		//删除命令
		for(var i=0;i<delcmds.length;++i)
		{
			delete this.cmdHash[delcmds[i]];
		}
	}
})


var g_cmdMgr=null;